package com.cnbot.toolkitmodel;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.util.Log;

import java.io.File;
import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {

	private static final String TAG = "MainActivity";

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		//		Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
		File file = new File(Environment.getExternalStorageDirectory() + "/ww/1.jpg");
		//		FileUtil.bitmap2File(bitmap, file, Bitmap.CompressFormat.JPEG, 50);
		File file2 = new File(Environment.getExternalStorageDirectory() + "/ww/2.png");
		//		FileUtil.bitmap2File(bitmap, file2, Bitmap.CompressFormat.PNG, 10);
		Bitmap bitmap1 = BitmapFactory.decodeFile(file.getAbsolutePath());
		Bitmap bitmap2 = BitmapFactory.decodeFile(file2.getAbsolutePath());
		Log.e(TAG, "bitmap1-" + bitmap1.getConfig() + "-bitmap2-" + bitmap2.getRowBytes());
	}

	private int floorMod(int x, int y) {
		return x - floorDiv(x, y) * y;
	}

	public int floorDiv(int x, int y) {
		int r = x / y;
		// if the signs are different and modulo not zero, round down
		if ((x ^ y) < 0 && (r * y != x)) {
			r--;
		}
		return r;
	}

	public class A<T> {
		private B b;
		private E e;
		private C<T> c;
		private ArrayList list = new ArrayList();

		public void set(B b) {
			this.b = b;
		}

		public C<T> init2() {
			return c = new C<>();
		}

		public void extract() {
			if (e != null) {
				e.face();
			}

			if (b != null) {
				b.insert();
			}
		}

		public void init() {
			list = b.queryAll();
		}
	}

	public class C<T> implements B<T> {

		@Override
		public void insert() {

		}

		@Override
		public ArrayList queryAll() {
			return null;
		}
	}

	public interface B<T> {
		void insert();

		ArrayList queryAll();
	}

	public interface D {
		void face();

	}

	public class E implements D {

		@Override
		public void face() {

		}

	}

	/**
	 * 某个文件是否以指定后缀结尾
	 * @param file
	 * @param suffix 后缀
	 */
	public static boolean checkSuffix(File file, String suffix) {
		if (file == null || TextUtils.isEmpty(suffix) || !file.exists() || file.isDirectory()) {
			return false;
		}
		String fileName = file.getName();
		return fileName.substring(fileName.lastIndexOf(".")).equals(suffix);
	}

	/**
	 * 获取某个文件的大小
	 * @param file
	 * @return
	 */
	public static long fileLength(File file) {
		if (file.exists() && file.isFile()) {
			return file.length();
		}
		return 0;
	}

}
